//中断函数+随机数 幸运66抽奖机
int a[10][7] = {
  { 1, 1, 1, 1, 1, 1, 0},
  { 0, 1, 1, 0, 0, 0, 0},
  { 1, 1, 0, 1, 1, 0, 1},
  { 1, 1, 1, 1, 0, 0, 1},
  { 0, 1, 1, 0, 0, 1, 1},
  { 1, 0, 1, 1, 0, 1, 1},
  { 1, 0, 1, 1, 1, 1, 1},
  { 1, 1, 1, 0, 0, 0, 0},
  { 1, 1, 1, 1, 1, 1, 1},
  { 1, 1, 1, 1, 0, 1, 1},
};

int no_a = 11;//右位
int no_b = 12;//左位
bool run_if = false;//是否运行
int rand_no = 0;
void setup() {
  //Serial.begin(115200);
  pinMode(no_a, OUTPUT);
  pinMode(no_b, OUTPUT);
  for (int i = 3; i <= 9; i++) {
    pinMode(i, OUTPUT);
    attachInterrupt(0,  auto_run_stop, FALLING);
  }
  // put your setup code here, to run once:

}

void  auto_run_stop() {
  run_if = !run_if ;
  delay(100);


}
void print_led(int t) { //t是对应的数字集合
  for (int j = 0; j <= 20; j++) {
    if (t < 10) {
      digitalWrite(no_a, 0);
      digitalWrite(no_b, 1);
      print_1no(t);
      //Serial.println(t);
      delay(4);

    }
    else {

      digitalWrite(no_a, 0);
      digitalWrite(no_b, 1);
      print_1no(t % 10);
      Serial.print(t % 10);
      delay(2);
      digitalWrite(no_a, 1);
      digitalWrite(no_b, 0);
      print_1no((t / 10 % 10));
      //Serial.println((t / 10  % 10));
      delay(2);

    }
  }
}

void print_1no(int t) {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(i + 3, a[t][i]);

  }
}
void loop() {
  // put your main code here, to run repeatedly:
  //for (int i = 0; i <= 99; i++) {
  //for (int j = 0; j <= 99; j++) {
  if (run_if == true) {
     print_led( 0);
     delay(1000);
    while (run_if == true) {
      rand_no = random (0, 99);
      if (run_if == true) {
        print_led( rand_no);
      }
      //delay(10);
    }
  }
  print_led( rand_no);
  //}
  //}

}